#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 1e6+10;
const int mod = 998244353;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
int n,m;
str s[maxn];
vector<bool > vis[maxn];
vector<bool > f[maxn];
void work(int x,int y) {
	f[x][y] = true;
	if(x) vis[x-1][y] = true;
	if(y) vis[x][y-1] = true;
	if(x+1 < n) vis[x+1][y] = true;
	if(y+1 < m) vis[x][y+1] = true;
}
void print() {
	int tot = 0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(s[i][j] == '.') cout<<'.';
			else cout<<f[i][j],tot+=f[i][j];
		}
		cout<<'\n';
	}
//	cerr<<tot<<'\n';
}
void Solve() {
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		vis[i].resize(m+1);
		f[i].resize(m+1);
	}
	bool fg = false;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++) fg |= (s[i][j] == '.');
	}
	if(!fg) {
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if((i+2*j)%5 == 0) work(i,j);
			}
		}
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				if(s[i][j] == '#' && !vis[i][j]) {
					work(i,j);
				}
			}
		}
		print();
		return;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(s[i][j] == '#' && !vis[i][j]) {
				work(i,j);
			}
		}
	}
	print();
}
int main() {
	freopen("indian.in","r",stdin);
	freopen("indian.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T = 1;
//	cin >> T;
	while(T--) {
		Solve();
	}
	return 0;
}
